<template>
  <div class="goods-list-container">
    <my-header title="商品列表"></my-header>
    <my-table :list="list">
      <template #header>
        <th>编号</th>
        <th>商品名称</th>
        <th>价格</th>
        <th>标签</th>
        <th>操作</th>
      </template>

      <template #body="scope">
        <td>{{ scope.row.id }}</td>
        <td>{{ scope.row.goods_name }}</td>
        <td>{{ scope.row.goods_price }}</td>
        <td>
          <span
            style="margin-left: 5px"
            class="badge bg-warning"
            v-for="(item, index) in scope.row.tags"
            :key="index"
            >{{ item }}</span
          >
        </td>
        <td>
          <button @click="del(scope.row.id)" class="btn btn-danger">
            删除
          </button>
        </td>
      </template>
    </my-table>
  </div>
</template>

<script>
import MyTable from "../components/MyTable.vue";
import MyHeader from "../components/MyHeader.vue";

export default {
  components: { MyHeader, MyTable },
  name: "GoodsListMygoodslist",

  data() {
    return {
      list: [],
    };
  },
  async created() {
    let res = await this.$http({
      url: "/api/goods",
    });
    this.list = res.data.data;
  },

  mounted() {},

  methods: {
    del(id) {
      let index = this.list.findIndex((item) => item.id == id);
      this.list.splice(index, 1);
    },
  },
};
</script>

<style lang="less" scoped>
.goods-list-container {
  padding: 45px 0 45px 0;
}
</style>